<!-- 蓝色简洁登录页面 -->
<template>
	<view class="login-bg">
		<view class="bg">
			
		</view>
		<view class="t-login">
			<view style="padding-top: 20rpx; padding-bottom: 20rpx; color: #1677FE; font-weight: 700; margin-top: -30rpx;">注册</view>
			<form class="cl">
				<view class="t-a">
					<image src="@/static/user.png"></image>
					<input type="number" name="phone" placeholder="请输入手机号码" maxlength="11" v-model="phone" />
				</view>
				<view class="t-a" style="position: relative;">
					<image src="@/static/code.png"></image>
					<input type="number" name="phone" placeholder="请输入验证码" maxlength="6" v-model="code" />
					<view @click="getCode" class="code">获取验证码</view>
				</view>
				<view class="t-a">
					<image src="@/static/pwd.png"></image>
					<input type="password" name="code" maxlength="6" placeholder="密码" v-model="pwd" />
				</view>
				<view class="t-a">
					<image src="@/static/pwd.png"></image>
					<input type="password" name="code" maxlength="6" placeholder="确认密码" v-model="pwd2" />
				</view>
				<button @tap="register()">注 册</button>
				<view class="t-c">
					<text class="t-c-txt" @tap="login()">已有账号？<text style="color: #2669EE;">去登录</text></text>
				</view>
			</form>
		</view>
	</view>
</template>
<script>
export default {
	/**
	 * 2020年12月9日  李新雷编写（练习）  适用所有app登录
	 * vue版本简洁又美观的登录页面（个人感觉插件市场的登录都不太好看，哈哈 O(∩_∩)O）
	 * 如果需要注册（注册可以设计在登录按钮下方），直接复制该页面稍微改动即可
	 */
	data() {
		return {
			code:'',
			phone: '', //手机号码
			pwd: '' ,//密码
			pwd2: '' //密码
			
		};
	},
	onLoad() {},
	methods: {
		//当前登录按钮操作
		register() {
			var that = this;
			if (!that.phone) {
				uni.showToast({ title: '请输入手机号', icon: 'none' });
				return;
			}
			if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(that.phone)) {
				uni.showToast({ title: '请输入正确手机号', icon: 'none' });
				return;
			}
			if (!that.code) {
				uni.showToast({ title: '请输入验证码', icon: 'none' });
				return;
			}
			if (!that.pwd) {
				uni.showToast({ title: '请输入密码', icon: 'none' });
				return;
			}
			if (!that.pwd2) {
				uni.showToast({ title: '请再次输入密码', icon: 'none' });
				return;
			}
			
			if(that.pwd!=that.pwd2){
				uni.showToast({ title: '两次密码不一致', icon: 'none' });
				return;
			}
			
			if (that.code!=123456) {
				uni.showToast({ title: '验证码错误', icon: 'none' });
				return;
			}
			
			uni.request({
				url:getApp().globalData.host+'srapi/home/register',
				method:'POST',
				data: { // 请求的参数
					phone:that.phone,pwd:that.pwd
				},
				header: { // 设置请求的header
					'content-type': 'application/json' // 默认值
				},
				success: (res) => {
					if(res.data.msg==''){
						uni.showToast({ title: '注册成功！', icon: 'none' });
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/my/login'
							})
						},2000)
						
					}else{
						uni.showToast({ title: res.data.msg, icon: 'none' });
					}
				}
			})
						
		},
		
		//去登录
		login() {
			uni.navigateTo({
				url:'/pages/my/login'
			})
		},
		getCode(){
			uni.showToast({ title: '验证码：123456', icon: 'none' });
		}
		
	}
};
</script>
<style>
.img-a {
	width: 100%;
	position: absolute;
	bottom: 0;
}
.login-bg {
	height: 100vh;
	background-color: #f8f8f8;
}
.bg{
	height: 20vh;
	background-image: url(../../static/bg.png);
}
.code{
	color: #fff;background-color: #2669EE;width: 30%;height: 100%; line-height: 300%; border-radius: 20rpx; position: absolute; text-align: center; top: 0;left: 70%;
}
.t-login {
	width: 580rpx;
	padding: 35rpx;
	margin: 0 auto;
	margin-top: -10vh;
	font-size: 28rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	box-shadow: 0 5px 7px 0 rgba(0, 0, 0, 0.15);
	z-index: 9;
}
.t-login button {
	font-size: 28rpx;
	/* background: linear-gradient(to right, #ff8f77, #fe519f); */
	background-color: #2669EE;
	color: #fff;
	height: 90rpx;
	line-height: 90rpx;
	border-radius: 20rpx;
}

.t-login input {
	padding: 0 20rpx 0 120rpx;
	height: 90rpx;
	line-height: 90rpx;
	margin-bottom: 50rpx;
	background: #f6f6f6;
	border: 1px solid #f6f6f6;
	font-size: 28rpx;
	border-radius: 20rpx;
}

.t-login .t-a {
	position: relative;
}

.t-login .t-a image {
	width: 40rpx;
	height: 40rpx;
	position: absolute;
	left: 40rpx;
	top: 28rpx;
	padding-right: 20rpx;
}

.t-login .t-b {
	text-align: left;
	font-size: 46rpx;
	color: #000;
	padding: 300rpx 0 120rpx 0;
	font-weight: bold;
}

.t-login .t-d {
	text-align: center;
	color: #999;
	margin: 80rpx 0;
}

.t-login .t-c {
	text-align: left;
	color: #666666;
	margin: 30rpx 30rpx 40rpx 0;
}

.t-login .t-c .t-c-txt {
	margin-right: 0rpx;
}

.t-login .t-e {
	text-align: center;
	width: 600rpx;
	margin: 40rpx auto 0;
}

.t-login .t-g {
	float: left;
	width: 33.33%;
}

.t-login .t-e image {
	width: 70rpx;
	height: 70rpx;
}

.t-login .t-f {
	text-align: center;
	margin: 80rpx 0 0 0;
	color: #999;
}

.t-login .t-f text {
	margin-left: 20rpx;
	color: #b9b9b9;
	font-size: 27rpx;
}

.t-login .uni-input-placeholder {
	color: #aeaeae;
}

.cl {
	zoom: 1;
}

.cl:after {
	clear: both;
	display: block;
	visibility: hidden;
	height: 0;
	content: '\20';
}
</style>
